home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / mbb35src / mbbsubr.asm < prev    next >
Encoding:
Assembly Source File  |  1987-11-07  |  8.3 KB  |  180 lines

  1. ;==========================================================================;
  2. ; Service subroutines                                                      ;
  3. ;                                                                          ;
  4. ;   Copyright 1983 by William E. Westfield.  All rights reserved.          ;
  5. ;   Copyright 1986 by H. Roy Engehausen.  All rights reserved.             ;
  6. ;   This software may be freely distributed and used, but it may not       ;
  7. ;   under any circumstances be sold by anyone other than the author.       ;
  8. ;   It may be distributed by a commercial company as long as it is         ;
  9. ;   for no cost.                                                           ;
  10. ;                                                                          ;
  11. ;   Permission is explicity granted to use this code as a model for        ;
  12. ;   other programs requiring interupt driven serial I/O as long as they    ;
  13. ;   carry this copyright notice.                                           ;
  14. ;==========================================================================;
  15.  
  16. ;==========================================================================;
  17. ; Get a buffer -- returns buffer segment in AX.  0 = no buffers available  ;
  18. ;        Uses AX                                                           ;
  19. ;==========================================================================;
  20.  
  21. get_a_buffer:
  22.  
  23.         MOV     AX,free_buffer_head ; Get head of buffer
  24.  
  25.         OR      AX,AX               ; Any there?
  26.         JZ      get_a_buffer_exit   ;      Nope....  Just return
  27.  
  28.         PUSH    ES                  ; Save ES
  29.         MOV     ES,AX               ; Point to the buffer we are about to use
  30.         MOV     ES,ES:buffer_next   ; Point to the next buffer
  31.         MOV     free_buffer_head,ES ; This is now the head
  32.         POP     ES                  ; Restore ES
  33.  
  34. get_a_buffer_exit:
  35.  
  36.         RET                         ; Bye bye
  37.  
  38. ;==========================================================================;
  39. ; Free a buffer -- buffer segment in AX.                                   ;
  40. ;        Uses AX.                                                          ;
  41. ;==========================================================================;
  42.  
  43. free_a_buffer:
  44.  
  45.         PUSH    ES                  ; Save ES
  46.         MOV     ES,AX               ;
  47.         MOV     AX,free_buffer_head ; Get head of current free chain
  48.         MOV     ES:buffer_next,AX   ; Add the one being freed to the front!
  49.         MOV     free_buffer_head,ES ; This is now the head
  50.         POP     ES                  ; Restore ES
  51.  
  52.         RET                         ; Bye bye
  53.  
  54. ;==========================================================================;
  55. ; Debugging service routine                                                ;
  56. ;==========================================================================;
  57.  
  58. dispchar:
  59.  
  60.         PUSH    AX                  ; Save registers
  61.         PUSH    BX                  ;
  62.         PUSH    BP                  ;
  63.         PUSH    SI                  ;
  64.         PUSH    DI                  ;
  65.  
  66.         MOV     BX,0                ; Select display page 0
  67.         MOV     AH,14               ; Function code for write
  68.         INT     10H                 ; Call video driver in bios
  69.  
  70.         POP     DI                  ; Restore regs
  71.         POP     SI                  ; Restore regs
  72.         POP     BP                  ; Restore regs
  73.         POP     BX                  ; Restore regs
  74.         POP     AX                  ; Restore regs
  75.  
  76.         RET                         ; To caller
  77.  
  78. disphex:
  79.  
  80.         PUSH    AX                  ; Save registers
  81.         PUSH    BX                  ;
  82.         PUSH    CX                  ;
  83.         PUSH    DX                  ;
  84.         PUSH    BP                  ;
  85.         PUSH    SI                  ;
  86.         PUSH    DI                  ;
  87.  
  88.         MOV     CH,AL               ; Save char
  89.         MOV     CL,4                ;
  90.         SHR     AL,CL               ;
  91.         SUB     BH,BH               ;
  92.         MOV     BL,AL               ;
  93.         MOV     AL,CS:hex[BX]       ;
  94.         SUB     BX,BX               ; Select display page 0
  95.         MOV     AH,14               ; Function code for write
  96.         INT     10H                 ; Call video driver in bios
  97.         MOV     BL,CH               ;
  98.         AND     BL,0FH              ;
  99.         MOV     AL,CS:hex[BX]       ;
  100.         SUB     BX,BX               ; Select display page 0
  101.         MOV     AH,14               ; Function code for write
  102.         INT     10H                 ; Call video driver in bios
  103.  
  104.  
  105.         POP     DI                  ; Restore regs
  106.         POP     SI                  ; Restore regs
  107.         POP     BP                  ; Restore regs
  108.         POP     DX                  ; Restore regs
  109.         POP     CX                  ; Restore regs
  110.         POP     BX                  ; Restore regs
  111.         POP     AX                  ; Restore regs
  112.  
  113.         RET                         ; To caller
  114.  
  115. hex     DB      '0123456789ABCDEF'                                                      ;
  116.  
  117. ;==========================================================================;
  118. ; Random number generator                                                  ;
  119. ;      Answer from 255 to 0 is in AL                                       ;
  120. ;==========================================================================;
  121.  
  122. r_seed  DD     2531011              ; Current Random number seed
  123. r_cons  DD     2531011              ; Constant to add to each generation
  124. r_mult  DD     214013               ; Constant multiplier for each generation
  125. r_ans   DQ     ?                    ; Holds the 8-byte answer for multiplication
  126.                                     ; (we only use the first six bytes).  The
  127.                                     ; algorithm for multiplying a 4-byte integer
  128.                                     ; by a 4-byte integer is included in its
  129.                                     ; entirety, but the instructions affecting
  130.                                     ; the high-order byte are commented out.
  131.  
  132. random:
  133.  
  134.         PUSH   DX                   ; Save the work register
  135.  
  136.         MOV    WORD PTR r_ans+4,0   ; Clear high-order answer words
  137. ;       MOV    WORD PTR r_ans+6,0   ; High-order word of ans is not used
  138.  
  139.         MOV    AX, WORD PTR r_seed  ; Get low order word of seed number (X)
  140.         MUL    WORD PTR r_mult      ; Multiply by low order word of multipler
  141.         MOV    WORD PTR r_ans,AX    ; Save low order answer
  142.         MOV    WORD PTR r_ans+2,DX  ; Save high order answer
  143.         MOV    AX, WORD PTR r_seed  ; Get low order word of seed number (X)
  144.         MUL    WORD PTR r_mult+2    ; Multiply by high order byte of multipler
  145.         ADD    WORD PTR r_ans+2,AX  ; Add to existing result
  146.         ADC    WORD PTR r_ans+4,DX  ;
  147. ;       JNC    nextmul
  148. ;       INC    WORD PTR r_ans+6     ; The high-order word is not used
  149. ;nextmul:
  150.  
  151.         MOV    AX,WORD PTR r_seed+2 ; Get high order word of seed
  152.         MUL    WORD PTR r_mult      ; Multiply by low order word of multipler
  153.         ADD    WORD PTR r_ans+2,AX  ; Add to existing result
  154.         ADC    WORD PTR r_ans+4,DX  ;
  155. ;       JNC    nextmulh
  156. ;       INC    WORD PTR r_ans+6     ; The high-order word is not used
  157. ;nextmulh:
  158.         MOV    AX,WORD PTR r_seed+2 ; Get high order word of seed.
  159.         MUL    WORD PTR r_mult+2    ; Multiply by high order word of multipler
  160.         ADD    WORD PTR r_ans+4,AX  ; Add to existing result
  161. ;       ADC    WORD PTR r_ans+6,DX  ; This word is not currently used in later
  162.                                     ;      calculations
  163.  
  164.         MOV    AX,WORD PTR r_cons   ; Add the constant to the result
  165.         ADD    WORD PTR r_ans,AX    ;
  166.         MOV    AX,WORD PTR r_cons+2 ;
  167.         ADC    WORD PTR r_ans+2,AX  ;
  168.  
  169.         MOV    AX,WORD PTR r_ans+2  ; We will use the low order dword for real
  170.         MOV    WORD PTR r_seed+2,AX ;      and save it for next time
  171.         MOV    DX,WORD PTR r_ans    ; Get low order word of r_answer
  172.         MOV    WORD PTR r_seed,DX   ;      and save it for next time
  173.  
  174.         POP    DX                   ; Restore the work register
  175.  
  176.         MOV    AL,AH                ; Use high order byte of r_ans+2
  177.  
  178.         RET                         ;
  179.  
  180.